package com.ruoyi.report.controller;

import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.report.domain.TCarouselImage;
import com.ruoyi.report.service.ITCarouselImageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 轮播图Controller
 * 
 * @author administrator
 * @date 2025-02-16
 */
@RestController
@RequestMapping("/project/image")
public class TCarouselImageController extends BaseController
{
    private String prefix = "project/image";

    @Autowired
    private ITCarouselImageService tCarouselImageService;

    @GetMapping()
    public String image()
    {
        return prefix + "/image";
    }

    /**
     * 查询轮播图列表
     */
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody TCarouselImage tCarouselImage)
    {
        startPage();
        List<TCarouselImage> list = tCarouselImageService.selectTCarouselImageList(tCarouselImage);
        return getDataTable(list);
    }

    /**
     * 导出轮播图列表
     */
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export( TCarouselImage tCarouselImage)
    {
        List<TCarouselImage> list = tCarouselImageService.selectTCarouselImageList(tCarouselImage);
        ExcelUtil<TCarouselImage> util = new ExcelUtil<TCarouselImage>(TCarouselImage.class);
        return util.exportExcel(list, "image");
    }

    /**
     * 新增轮播图
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存轮播图
     */
    @PostMapping("/add")
    public AjaxResult addSave(@RequestBody TCarouselImage tCarouselImage)
    {
        return toAjax(tCarouselImageService.insertTCarouselImage(tCarouselImage));
    }

    /**
     * 修改轮播图
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TCarouselImage tCarouselImage = tCarouselImageService.selectTCarouselImageById(id);
        mmap.put("tCarouselImage", tCarouselImage);
        return prefix + "/edit";
    }

    /**
     * 修改保存轮播图
     */
    @PostMapping("/edit")
    public AjaxResult editSave(@RequestBody TCarouselImage tCarouselImage)
    {
        return toAjax(tCarouselImageService.updateTCarouselImage(tCarouselImage));
    }

    /**
     * 删除轮播图
     */
    @PostMapping( "/remove")
    public AjaxResult remove(@RequestBody Map<String,String> map)
    {
        return toAjax(tCarouselImageService.deleteTCarouselImageByIds(map));
    }
}
